package com.bysj.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bysj.system.mapper.HouseListingMapper;
import com.bysj.system.domain.HouseListing;
import com.bysj.system.service.IHouseListingService;

/**
 * 房源Service业务层处理
 *
 * @author bysj
 * @date 2024-02-03
 */
@Service
public class HouseListingServiceImpl implements IHouseListingService
{
    @Autowired
    private HouseListingMapper houseListingMapper;

    /**
     * 查询房源
     *
     * @param id 房源主键
     * @return 房源
     */
    @Override
    public HouseListing selectHouseListingById(Long id)
    {
        return houseListingMapper.selectHouseListingById(id);
    }

    /**
     * 查询房源列表
     *
     * @param houseListing 房源
     * @return 房源
     */
    @Override
    public List<HouseListing> selectHouseListingList(HouseListing houseListing)
    {
        return houseListingMapper.selectHouseListingList(houseListing);
    }

    /**
     * 新增房源
     *
     * @param houseListing 房源
     * @return 结果
     */
    @Override
    public int insertHouseListing(HouseListing houseListing)
    {
//        更改地区编号为真实地区名字
        String provinceName = houseListingMapper.selectProvince(Long.parseLong(houseListing.getProvince()));
        String cityName = houseListingMapper.selectCity(Long.parseLong(houseListing.getCity()));
        String districtName = houseListingMapper.selectDistrict(Long.parseLong(houseListing.getDistrict()));
        houseListing.setProvince(provinceName);
        houseListing.setCity(cityName);
        houseListing.setDistrict(districtName);
        houseListing.setCollectionCount(0L);

        return houseListingMapper.insertHouseListing(houseListing);
    }

    /**
     * 修改房源
     *
     * @param houseListing 房源
     * @return 结果
     */
    @Override
    public int updateHouseListing(HouseListing houseListing)
    {
        return houseListingMapper.updateHouseListing(houseListing);
    }

    /**
     * 批量删除房源
     *
     * @param ids 需要删除的房源主键
     * @return 结果
     */
    @Override
    public int deleteHouseListingByIds(Long[] ids)
    {
        return houseListingMapper.deleteHouseListingByIds(ids);
    }

    /**
     * 删除房源信息
     *
     * @param id 房源主键
     * @return 结果
     */
    @Override
    public int deleteHouseListingById(Long id)
    {
        return houseListingMapper.deleteHouseListingById(id);
    }
}
